package com.kmxd.ams.app.event.archive.command;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kmxd.ams.app.event.AmsEventPublisher;
import com.kmxd.ams.client.archive.*;
import com.kmxd.ams.client.event.es.EsCreateIndexEvent;
import com.kmxd.ams.client.system.dto.SysFondsAddDTO;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.common.enums.DbTypeEnum;
import com.kmxd.ams.core.config.AmsConfig;
import com.kmxd.ams.core.exception.BizTipException;
import com.kmxd.ams.infra.archive.entity.*;
import com.kmxd.ams.infra.arrange.entity.Box;
import com.kmxd.ams.infra.arrange.entity.Document;
import com.kmxd.ams.infra.arrange.entity.Project;
import com.kmxd.ams.infra.arrange.entity.Volume;
import com.kmxd.ams.infra.system.entity.SysFonds;
import com.kmxd.ams.infra.system.mapper.SysFondsMapper;
import com.kmxd.ams.infra.tmpl.dto.ArchTmplBO;
import com.kmxd.ams.infra.tmpl.dto.JsonFieldDto;
import com.kmxd.ams.infra.tmpl.enums.TmplEnum;
import com.kmxd.ams.infra.tmpl.util.CreateTableUtils;
import com.kmxd.ams.infra.tmpl.util.ExtFieldUtil;
import com.kmxd.ams.infra.tmpl.util.TmplUtils;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.jetbrains.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * 复制全宗相关档案库
 *
 * @author ZuoLG
 */
@Slf4j
@RequiredArgsConstructor
@Component
public class CopyFondsCmd {
  private final SysFondsMapper sysFondsMapper;
  private final IArchiveTypeSvc archiveTypeSvc;
  /** 规则主表 */
  private final IArchiveRuleMainSvc archiveRuleMainSvc;
  /** 规则字段 */
  private final IArchiveRuleFieldSvc archiveRuleFieldSvc;
  /** 分类及保管期限 */
  private final IArchiveClassifySvc archiveClassifySvc;
  /** 版本 */
  private final IArchiveVersionSvc archiveVersionSvc;
  /** 元数据方案 */
  private final IArchiveFieldSvc archiveFieldSvc;
  /** 目录配置 */
  private final IArchiveRuleCatalogSvc archiveRuleCatalogSvc;
  /** 排序字段 */
  private final IArchiveOrderFieldSvc archiveOrderFieldSvc;
  /** 关联设置 */
  private final IArchiveRelationSettingSvc archiveRelationSettingSvc;
  /** 附件设置 */
  private final IArchiveOssSettingSvc archiveOssSettingSvc;
  /** 水印信息 */
  private final IArchiveWatermarkSvc archiveWatermarkSvc;

  /** 元数据对应 --后续 */
  private final IArchiveMetaFieldMainSvc archiveMetaFieldMainSvc;
  /** 元数据对应明细 --后续 */
  private final IArchiveMetaFieldDetailSvc archiveMetaFieldDetailSvc;

  /** 附件配置 */
  private final IArchiveRuleAttachmentSvc archiveRuleAttachmentSvc;

  // 通用权限
  private final IArchiveAuthSvc archiveAuthSvc;

  private final CreateTableUtils createTableUtils;
  private final JdbcTemplate jdbcTemplate;
  private final CreateTableUtils ctu;
  private final TmplUtils tmplUtils;
  private final AmsConfig amsConfig;
  private final AmsEventPublisher amsEventPublisher;
  /**
   * 复制档案库相关内容
   *
   * @param entity
   * @param req
   * @return
   */
  public boolean initCopy(SysFonds entity, SysFondsAddDTO req) {
    // 1、查询选中的档案库，并新增
    List<ArchiveType> archiveTypes = copyFonds(req);
    List<ArchiveVersion> listVersion = getVersion(req);
    List<ArchiveRuleMain> listRuleMain = getRuleMain(req);
    List<ArchiveRuleField> listRuleField = getRuleField(req);
    List<ArchiveClassify> listClassify = getClassify(req);
    List<ArchiveRuleCatalog> listRuleCatalog = getArchiveRuleCatalog(req);
    List<ArchiveOrderField> listOrderField = getOrderField(req);
    List<ArchiveField> listField = getField(req);
    List<ArchiveRelationSetting> listRelationSetting = getRelationSetting(req);
    List<ArchiveOssSetting> listOssSetting = getOssSetting(req);
    List<ArchiveWatermark> listWatermark = getWatermark(req);

    // 待定
    List<ArchiveMetaFieldMain> listMetaFieldMain = getMetaFieldMain(req);

    archiveTypes.forEach(
        archType -> {
          try {
            Long oldId = archType.getId();
            Long oldFondsId = archType.getFondsId();
            // 2、查询整理规则  // 3、归档范围及保管期限  // 4、元数据内容
            archType.setId(IdWorker.getId());
            archType.setComId(entity.getComId());
            archType.setFondsId(entity.getId());
            archType.setSort(
                (int) archiveTypeSvc.countArchTypeByFondsId(archType.getFondsId()) + 1);
            // 处理表名
            String docTableName =
                archiveTypeSvc.getTableName(archType.getFondsId(), ArchTmplBO.DOCUMENT);
            archType.setDocTableId(docTableName);
            if (archType.getHaveBox()) {
              archType.setBoxTableId(
                  archiveTypeSvc.getTableName(archType.getFondsId(), ArchTmplBO.BOX));
            }
            if (archType.getHaveVol()) {
              archType.setVolTableId(
                  archiveTypeSvc.getTableName(archType.getFondsId(), ArchTmplBO.VOLUME));
            }
            if (archType.getHaveProject()) {
              archType.setProjTableId(
                  archiveTypeSvc.getTableName(archType.getFondsId(), ArchTmplBO.PROJECT));
            }
            archiveTypeSvc.save(archType);
            // 1、更新版本信息
            List<ArchiveVersion> verItem =
                listVersion.stream()
                    .filter(v -> v.getArchiveTypeId().equals(oldId))
                    .collect(Collectors.toList());
            // 2、更新规则及规则字段
            List<ArchiveRuleField> ruleFields =
                listRuleField.stream()
                    .filter(v -> v.getArchTypeId().equals(oldId))
                    .map(
                        item -> {
                          item.setId(IdWorker.getId());
                          item.setArchTypeId(archType.getId());
                          // 表名处理
                          String tableName = getTableName(archType, item.getTableId());
                          item.setTableId(tableName);
                          return item;
                        })
                    .collect(Collectors.toList());
            // 规则主表
            List<ArchiveRuleMain> ruleMains =
                listRuleMain.stream()
                    .filter(v -> v.getArchTypeId().equals(oldId))
                    .map(
                        item -> {
                          Long newId = IdWorker.getId();
                          // 配置型的规则ID
                          ruleFields.forEach(
                              field -> {
                                if (ObjectUtil.equals(field.getRuleId(), item.getId())) {
                                  field.setRuleId(newId);
                                }
                              });
                          item.setId(newId);
                          item.setArchTypeId(archType.getId());
                          return item;
                        })
                    .collect(Collectors.toList());
            archiveRuleMainSvc.saveBatch(ruleMains);
            archiveRuleFieldSvc.saveBatch(ruleFields);

            /** 分类版本 */
            List<ArchiveVersion> versionList = Lists.newArrayList();
            verItem.stream()
                .filter(vv -> vv.getArchiveTypeId().equals(oldId))
                .forEach(
                    ver -> {
                      long verOldId = ver.getId();
                      long verNewId = IdWorker.getId();
                      ver.setId(verNewId);
                      ver.setFondsId(archType.getFondsId());
                      ver.setArchiveTypeId(archType.getId());
                      versionList.add(ver);
                      // 3、 归档期限及分类 listClassify ,按照当前分类过滤
                      List<ArchiveClassify> classifys =
                          listClassify.stream()
                              .filter(
                                  x ->
                                      x.getArchiveTypeId().equals(oldId)
                                          && ObjectUtil.equals(x.getVersionId(), verOldId))
                              .map(
                                  item -> {
                                    item.setFondsId(archType.getFondsId());
                                    item.setArchiveTypeId(archType.getId());
                                    item.setVersionId(verNewId);
                                    return item;
                                  })
                              .collect(Collectors.toList());
                      // 处理层级问题
                      forClassify(classifys, 0L, 0L);

                      archiveClassifySvc.saveBatch(classifys);
                    });

            // 添加版本
            archiveVersionSvc.saveBatch(versionList);

            // 4、 目录设置
            archiveRuleCatalogSvc.initArchNode(archType.getId());
            // 5、排序
            List<ArchiveOrderField> orderFields =
                listOrderField.stream()
                    .filter(v -> v.getArchTypeId().equals(oldId))
                    .map(
                        item -> {
                          Long newId = IdWorker.getId();
                          item.setId(newId);
                          //  表名处理
                          String tableName = getTableName(archType, item.getTableId());
                          item.setTableId(tableName);
                          item.setArchTypeId(archType.getId());
                          return item;
                        })
                    .collect(Collectors.toList());
            archiveOrderFieldSvc.saveBatch(orderFields);

            // 6、元数据字段
            List<ArchiveField> fields =
                listField.stream()
                    .filter(v -> v.getArchTypeId().equals(oldId))
                    .map(
                        item -> {
                          Long newId = IdWorker.getId();
                          item.setId(newId);
                          //  表名处理
                          String tableName = getTableName(archType, item.getTableId());
                          item.setTableId(tableName);
                          item.setExtendsTableId(getTableName(archType, item.getExtendsTableId()));
                          item.setArchTypeId(archType.getId());
                          return item;
                        })
                    .collect(Collectors.toList());
            archiveFieldSvc.saveBatch(fields);

            // 7、关联关系
            List<ArchiveRelationSetting> relationSettings =
                listRelationSetting.stream()
                    .filter(v -> v.getArchTypeId().equals(oldId))
                    .map(
                        item -> {
                          Long newId = IdWorker.getId();
                          item.setId(newId);
                          //  表名处理
                          String tableName = getTableName(archType, item.getTableId());
                          item.setTableId(tableName);
                          item.setArchTypeId(archType.getId());
                          return item;
                        })
                    .collect(Collectors.toList());
            archiveRelationSettingSvc.saveBatch(relationSettings);

            // 8、附件配置
            List<ArchiveOssSetting> ossSettings =
                listOssSetting.stream()
                    .filter(v -> v.getArchTypeId().equals(oldId))
                    .map(
                        item -> {
                          Long newId = IdWorker.getId();
                          item.setId(newId);
                          // 处理关联关系字段,新修改后不需要处理
                          item.setArchTypeId(archType.getId());
                          return item;
                        })
                    .collect(Collectors.toList());
            archiveOssSettingSvc.saveBatch(ossSettings);

            // 动态创建表
            Map<String, List<ArchiveField>> filedGroup =
                fields.stream().collect(Collectors.groupingBy(ArchiveField::getTableId));
            // key 为表名，list为字段
            filedGroup.forEach(
                (tableName, list) -> {
                  list.stream().sorted();
                  // 过滤掉ext扩展相关的
                  List<JsonFieldDto> tableField =
                      list.stream()
                          .filter(item -> !item.getDbFieldKey().contains("ext_"))
                          .map(
                              item -> {
                                JsonFieldDto jsonFieldDto =
                                    BeanUtil.copyProperties(item, JsonFieldDto.class);
                                jsonFieldDto.setCode(item.getDbFieldKey());
                                jsonFieldDto.setType(item.getDbType());
                                jsonFieldDto.setLength(item.getDbLength());
                                jsonFieldDto.setDefaultvalue(item.getDbDefault());
                                jsonFieldDto.setName(item.getDbFieldName());
                                return jsonFieldDto;
                              })
                          .collect(Collectors.toList());
                  // 添加扩展字段
                  List<JsonFieldDto> extFields =
                      ExtFieldUtil.getExtField(
                          tableName.contains(ArchTmplBO.DOCUMENT)
                              ? Document.class
                              : tableName.contains(ArchTmplBO.VOLUME)
                                  ? Volume.class
                                  : tableName.contains(ArchTmplBO.BOX)
                                      ? Box.class
                                      : tableName.contains(ArchTmplBO.PROJECT)
                                          ? Project.class
                                          : null);
                  if (!extFields.isEmpty()) {
                    tableField.addAll(extFields);
                  }
                  tableField.stream().sorted();
                  String tableSchema;
                  int count = 0;
                  if (StrUtil.isBlank(amsConfig.getDbType())
                      || StrUtil.equals(DbTypeEnum.MYSQL.getCode(), amsConfig.getDbType())) {
                    tableSchema = sysFondsMapper.getDataBaseId();
                    count = sysFondsMapper.haveEfileTable(tableSchema, tableName);
                  } else {
                    tableSchema = amsConfig.getDbName();
                    count = sysFondsMapper.haveEfileTablePG(tableSchema, tableName);
                  }
                  if (count != 0) {
                    throw BizTipException.instance(
                        ErrorCode.ARCHIVE_DATA_EXIST,
                        StrUtil.format("表:[{}]已经存在，请手动处理!", tableName));
                  }
                  String sql;
                  if (StrUtil.isBlank(amsConfig.getDbType())
                      || StrUtil.equals(DbTypeEnum.MYSQL.getCode(), amsConfig.getDbType())) {
                    sql = createTableUtils.getTableSql(tableName, req.getName(), tableField);
                  } else {
                    sql = createTableUtils.getTableSqlPg(tableName, req.getName(), tableField);
                  }
                  jdbcTemplate.execute(sql);
                });

            // 9、复制其他相关配置
            // 9.1、水印配置 复制水印
            List<ArchiveWatermark> watermarks =
                listWatermark.stream()
                    .filter(v -> v.getArchTypeId().equals(oldId))
                    .map(
                        item -> {
                          Long newId = IdWorker.getId();
                          item.setId(newId);
                          item.setArchTypeId(archType.getId());
                          return item;
                        })
                    .collect(Collectors.toList());
            if (req.getOtherConfig().contains("watermark")) {
              archiveWatermarkSvc.saveBatch(watermarks);
            }
            // 9.1复制流程
            if (req.getOtherConfig().contains("flow")) {}

            // 10 复制通用权限
            if (req.getOtherConfig().contains("auth")) {
              List<ArchiveAuth> listAuth = getAuth(req);
              List<ArchiveAuth> auths =
                  listAuth.stream()
                      .filter(v -> v.getArchTypeId().equals(oldId))
                      .map(
                          item -> {
                            Long newId = IdWorker.getId();
                            item.setId(newId);
                            item.setArchTypeId(archType.getId());
                            return item;
                          })
                      .collect(Collectors.toList());
              archiveAuthSvc.saveBatch(auths);
            }
            // 创建es索引
            // 门类创建,删除存在的index,重新创建
            amsEventPublisher.publishEvent(
                new EsCreateIndexEvent(archType.getId().toString(), true));
          } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
          }
        });
    return true;
  }

  public boolean initCopyFonds(SysFonds sysFonds, SysFondsAddDTO req) {
    // 判断是否是复制
    if (BooleanUtil.isTrue(req.getCopyFlag())) {
      SysFondsAddDTO fondsAddDTO = BeanUtil.copyProperties(sysFonds, SysFondsAddDTO.class);
      fondsAddDTO.setCopyFlag(req.getCopyFlag());
      fondsAddDTO.setCopyFondsId(req.getCopyFondsId());
      fondsAddDTO.setArchType(req.getArchType());
      fondsAddDTO.setOtherConfig(req.getOtherConfig());
      // 复制档案配置逻辑
      CopyFondsCmd copyFondsCmd = SpringUtil.getBean(CopyFondsCmd.class);
      copyFondsCmd.initCopy(sysFonds, fondsAddDTO);
    }
    // 判断电子文件是否存在,// 新建电子文件表
    String tableName = TmplEnum.efile.getCode() + "_" + sysFonds.getAutoIndex();
    String tableSchema;
    int count = 0;
    if (StrUtil.isBlank(amsConfig.getDbType())
        || StrUtil.equals(DbTypeEnum.MYSQL.getCode(), amsConfig.getDbType())) {
      tableSchema = sysFondsMapper.getDataBaseId();
      count = sysFondsMapper.haveEfileTable(tableSchema, tableName);
    } else {
      tableSchema = amsConfig.getDbName();
      count = sysFondsMapper.haveEfileTablePG(tableSchema, tableName);
    }
    if (count != 0) {
      throw BizTipException.instance(
          ErrorCode.ARCHIVE_DATA_EXIST, StrUtil.format("电子文件表:[{}]已经存在，请手动处理!", tableName));
    }
    tmplUtils
        .getTmpl(TmplEnum.efile.getCode())
        .forEach(
            tmpl -> {
              try {
                String sql;
                if (StrUtil.isBlank(amsConfig.getDbType())
                    || StrUtil.equals(DbTypeEnum.MYSQL.getCode(), amsConfig.getDbType())) {
                  sql = ctu.getTableSql(tableName, req.getName(), tmpl.getFields());
                } else {
                  sql = ctu.getTableSqlPg(tableName, req.getName(), tmpl.getFields());
                }
                jdbcTemplate.execute(sql);
              } catch (BizTipException e) {
                log.error(e.getMessage(), e);
              } catch (DataAccessException e) {
                throw BizTipException.instance(
                    ErrorCode.VALIDATE_ERROR, StrUtil.format("创建电子文件异常!", e.getMessage()));
              }
            });

    archiveTypeSvc.clearAllCache();

    return true;
  }

  /** 处理分类问题 */
  private void forClassify(List<ArchiveClassify> classifys, Long pid, Long newPid) {
    classifys.stream()
        .filter(x -> ObjectUtil.equals(x.getPid(), pid))
        .forEach(
            item -> {
              long oldId = item.getId();
              long newId = IdWorker.getId();
              item.setId(newId);
              item.setPid(newPid);
              forClassify(classifys, oldId, newId);
            });
  }

  /**
   * 动态判断获取表名
   *
   * @param archType
   * @param tableId
   * @return
   */
  @Nullable
  private String getTableName(ArchiveType archType, String tableId) {
    if (ObjectUtil.isEmpty(tableId)) {
      return tableId;
    }
    return tableId.contains(ArchTmplBO.DOCUMENT)
        ? archType.getDocTableId()
        : tableId.contains(ArchTmplBO.VOLUME)
            ? archType.getVolTableId()
            : tableId.contains(ArchTmplBO.BOX)
                ? archType.getBoxTableId()
                : tableId.contains(ArchTmplBO.PROJECT) ? archType.getProjTableId() : null;
  }

  /**
   * 规则字段
   *
   * @param req
   * @return
   */
  private List<ArchiveRuleField> getRuleField(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveRuleField> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveRuleField::getArchTypeId, req.getArchType());
    return this.archiveRuleFieldSvc.list(queryWrapper);
  }

  /**
   * 获取通用权限
   *
   * @param req
   * @return
   */
  private List<ArchiveAuth> getAuth(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveAuth> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveAuth::getArchTypeId, req.getArchType());
    return this.archiveAuthSvc.list(queryWrapper);
  }

  /**
   * 水印信息
   *
   * @param req
   * @return
   */
  private List<ArchiveWatermark> getWatermark(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveWatermark> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveWatermark::getArchTypeId, req.getArchType());
    return this.archiveWatermarkSvc.list(queryWrapper);
  }

  /**
   * 元数据对应
   *
   * @param req
   * @return
   */
  private List<ArchiveMetaFieldMain> getMetaFieldMain(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveMetaFieldMain> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveMetaFieldMain::getArchTypeId, req.getArchType());
    return this.archiveMetaFieldMainSvc.list(queryWrapper);
  }

  /**
   * 分类及保管期限
   *
   * @param req
   * @return
   */
  private List<ArchiveClassify> getClassify(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveClassify> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveClassify::getArchiveTypeId, req.getArchType());
    return this.archiveClassifySvc.list(queryWrapper);
  }

  /**
   * 附件设置
   *
   * @param req
   * @return
   */
  private List<ArchiveOssSetting> getOssSetting(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveOssSetting> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveOssSetting::getArchTypeId, req.getArchType());
    return this.archiveOssSettingSvc.list(queryWrapper);
  }

  /**
   * 关联设置
   *
   * @param req
   * @return
   */
  private List<ArchiveRelationSetting> getRelationSetting(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveRelationSetting> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveRelationSetting::getArchTypeId, req.getArchType());
    return this.archiveRelationSettingSvc.list(queryWrapper);
  }

  /**
   * 排序字段
   *
   * @param req
   * @return
   */
  private List<ArchiveOrderField> getOrderField(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveOrderField> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveOrderField::getArchTypeId, req.getArchType());
    return this.archiveOrderFieldSvc.list(queryWrapper);
  }

  /**
   * 目录配置
   *
   * @param req
   * @return
   */
  private List<ArchiveRuleCatalog> getArchiveRuleCatalog(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveRuleCatalog> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveRuleCatalog::getArchTypeId, req.getArchType());
    return this.archiveRuleCatalogSvc.list(queryWrapper);
  }

  /**
   * 元数据方案
   *
   * @param req
   * @return
   */
  private List<ArchiveField> getField(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveField> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveField::getArchTypeId, req.getArchType());
    return this.archiveFieldSvc.list(queryWrapper);
  }

  /**
   * 查询规则主表
   *
   * @param req
   * @return
   */
  private List<ArchiveRuleMain> getRuleMain(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveRuleMain> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveRuleMain::getArchTypeId, req.getArchType());
    return this.archiveRuleMainSvc.list(queryWrapper);
  }

  /**
   * 版本
   *
   * @param req
   * @return
   */
  private List<ArchiveVersion> getVersion(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveVersion> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.in(ArchiveVersion::getArchiveTypeId, req.getArchType());
    return this.archiveVersionSvc.list(queryWrapper);
  }

  /**
   * 查询复制的全宗档案库
   *
   * @param req
   * @return
   */
  private List<ArchiveType> copyFonds(SysFondsAddDTO req) {
    LambdaQueryWrapper<ArchiveType> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.eq(
        Objects.nonNull(req.getCopyFondsId()), ArchiveType::getFondsId, req.getCopyFondsId());
    queryWrapper.in(ArchiveType::getId, req.getArchType());
    return this.archiveTypeSvc.list(queryWrapper);
  }
}
